package com.bainarm.testteabarmachine;

import androidx.appcompat.app.AppCompatActivity;
import com.bainarm.library_fragment.LogFragment;
import com.bainarm.library_fragment.OkNgButtonsFragment;
import com.bainarm.library_fragment.VideoFragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class SingleTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_test);

        // 初始化界面组件
        initializeViews();

    }

    // 初始化界面组件
    private void initializeViews(){
        addLogFragment();
//        addVideoFragment();
        addOkNgButtonsFragment();

        btnExitListener(); // 返回按钮
    }

    /***************按钮监听事件***********************/

    private void btnExitListener(){
        TextView btnExit = findViewById(R.id.btnExit);
        btnExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // 返回到首页的逻辑，例如
                navigateToHomeActivity();

            }
        });
    }

    // 跳转首页逻辑
    private void navigateToHomeActivity() {
        Intent intent = new Intent(SingleTestActivity.this, HomeActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        // TODO 清理登录记录
        finish();  // 结束当前活动
    }


    /******************** add fragment **************************/

    // 创建和显示日志fragment
    private void addLogFragment(){
        LogFragment logFragment = new LogFragment();
        getSupportFragmentManager().beginTransaction()
                .add(R.id.logFragmentContainer, logFragment)
                .commit();
    }

    // 创建和显示视频Fragment
    private void addVideoFragment(){
        VideoFragment videoFragment = new VideoFragment();
        getSupportFragmentManager().beginTransaction()
                .add(R.id.videoFragmentContainer, videoFragment)
                .commit();
    }

    // 创建和显示OkNg按钮Fragment
    private void addOkNgButtonsFragment(){
        OkNgButtonsFragment okNgButtonsFragment = new OkNgButtonsFragment();
        getSupportFragmentManager().beginTransaction()
                .add(R.id.buttonFragmentContainer, okNgButtonsFragment)
                .commit();
    }



}